package com.alogic.cron.matcher;

import com.alogic.cron.CronMatcher;
import com.anysoft.util.DefaultProperties;
import com.anysoft.util.Properties;
import com.anysoft.util.PropertiesConstants;

/**
 * 调度时间匹配器(间隔)
 * 
 * @author duanyy
 * @since 1.6.13.7 [20200720 duanyy] <br>
 */
public class Interval extends CronMatcher.Abstract {
	/**
	 * 间隔时间，可通过参数interval配置
	 */
	protected long interval = 1000;
	
	public Interval(){

	}

	public Interval(String expr){
		DefaultProperties p = new DefaultProperties();
		p.loadFromString(expr,";","=");
		configure(p);
	}
	
	public Interval(long _interval){
		interval = _interval;
	}
	
	public void configure(Properties p) {
		interval = PropertiesConstants.getLong(p,"interval",interval);
	}

	@Override
	public boolean match(long lastDate, long now) {
		return lastDate <= 0 ? true:((now - lastDate) >= interval);
	}
}
